package com.zzn.bookManage.util;

import com.zzn.bookManage.service.BookService;
import com.zzn.bookManage.service.UserService;
import com.zzn.bookManage.service.impl.BookServiceImpl;
import com.zzn.bookManage.service.impl.UserServiceImpl;

public class ObjectHolder {
    private final BookService BookService;
    private final UserService userService;
    private final MyProperties config;

    private static ObjectHolder instance;

    /**
     * 单例模式 优化对象创建
     * @return
     */
    public static ObjectHolder getInstance(){
        if (instance == null){
            instance = new ObjectHolder();
        }
        return instance;
    }

    private ObjectHolder() {
        this.BookService = new BookServiceImpl();
        this.userService = new UserServiceImpl();
        this.config = MyProperties.getInstance(null);
    }

    public BookService getBookService() {
        return BookService;
    }

    public UserService getUserService() {
        return userService;
    }

    public MyProperties getConfig() {
        return config;
    }
}
